# 获取网页源码
import requests
# 实例化源码  进行解析
from lxml import etree
# 下载所需要的资源
import urllib.request


def install(url):
    respons = requests.get(url)
    respons.encoding = "utf-8"
    # respons.text   网页源码
    tree = etree.HTML(respons.text)
    img_list = tree.xpath("//ul[@class='ali']/li")
    for i in img_list:
        img_url = i.xpath(".//img/@src")[0]
        img_name = i.xpath(".//img/@alt")[0]
        filename = "tianTang_img/" + img_name + ".jpg"
        url = "https:" + img_url
        urllib.request.urlretrieve(url=url, filename=filename)
        print(url + "==================" + filename)


if __name__ == '__main__':
    for i in range(1, 11):
        url = "https://www.ivsky.com/tupian/ziranfengguang/index_" + str(i) + ".html"
        install(url)
